@extends('layouts.base')

@section('title', '权限')

@section('admin-style')
	<link rel="stylesheet" href="{{ asset('/assets/plugins/dropify/dist/css/dropify.min.css') }}">
@stop

@section('content')
<div class="container-fluid">
	<!-- ============================================================== -->
	<!-- Bread crumb and right sidebar toggle -->
	<!-- ============================================================== -->
	<div class="row page-titles">
	    <div class="col-md-5 align-self-center">
	        <h3 class="text-themecolor">权限--添加</h3>
	    </div>
	    <div class="col-md-7 align-self-center">
	        <ol class="breadcrumb">
	            <li class="breadcrumb-item"><a href="javascript:void(0)">首页</a></li>
	            <li class="breadcrumb-item">权限管理</li>
	            <li class="breadcrumb-item active">权限添加</li>
	        </ol>
	    </div>
	</div>
	<div class="row">
	    <div class="col-lg-12">
	        <div class="card">
            	<div class="card-header bg-success">
                    <h4 class="m-b-0 text-white">添加</h4>
                </div>
                <div class="card-body"></div>
                <div class="card-body">
                    <form class="needs-validation" method="post" action="{{ route('admin.permissions.store') }}" novalidate enctype="multipart/form-data">  
                        @csrf
                    	<div class="form-body">
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">上级权限：</label>
                                <div class="col-md-7">
                                    <select name="parent_id" id="select" class="form-control" aria-invalid="false">
                                        <option value="0">顶级权限</option>
                                        @foreach($parents as $parent)
                                            <option value="{{ $parent['id'] }}">{{ $parent['name'] }}</option>
                                            @if(isset($parent['children']))
                                                @foreach($parent['children'] as $item)
                                                    <option value="{{ $item['id'] }}">{{ "  |--".$item['name'] }}</option>
                                                @endforeach
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                            </div>  
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">权限名称：</label>
                                <div class="col-md-7">
                                    <input type="text" class="form-control{{ $errors->has('title') ? ' is-invalid' : '' }}" id="" name="title" placeholder="权限名称" value="{{ old('title') }}" required>
                                    @if ($errors->has('title'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('title') }}</strong>
                                        </span>
                                    @endif
                                    <div class="invalid-feedback">
                                       请填写权限名称
                                    </div>
                                </div>
                            </div>  
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">标识：</label>
                                <div class="col-md-7">
                                    <input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" id="" placeholder="标识" value="{{ old('name', 'not_show') }}" >
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">介绍：</label>
                                <div class="col-md-7">
                                    <textarea name="description" id="textarea" class="form-control" placeholder="介绍"></textarea>
                                </div>
                            </div>
                        </div>                  
                      	<div class="form-actions">
                            <div class="row">
                                <div class="col-md-8">
                                    <div class="row">
                                        <div class="offset-sm-3 col-md-9">
                                            <button type="submit" class="btn btn-success"> <i class="fa fa-check"></i> 提交</button>
                                            <a href="{{ route('admin.permissions.index') }}"><button type="button" class="btn btn-danger"><i class=" fas fa-times"></i> 取消</button></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
	    </div>
	</div>
</div>
@stop

@section('admin-js')

<!--Custom JavaScript -->
<script src="{{ asset('assets/js/validation.js') }}"></script>
<!-- jQuery file upload -->

<script>
//For validation with custom styles
(function() {
  'use strict';
  window.addEventListener('load', function() {
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
        if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);
  
})();
</script>
@stop